package main

import (
	"fmt"
	"strconv"
	"strings"
)

//累加器
func AddUpper() func(int) int {
	n := 10
	str := "string"
	return func(x int) int {
		n = n + x
		str += strconv.Itoa(x)
		fmt.Println(str)
		return n
	}
}

func makeSuffix(suffix string) func (string) string{
	return func (name string) string{
		if !strings.HasSuffix(name, suffix){
			return name + suffix
		}
		return name
	}
}

func makeSuffix2(name , suffix string) string {
	if !strings.HasSuffix(name, suffix){
		return name + suffix
	}
	return name
}

func main() {
	f := AddUpper()
	fmt.Println(f(1))
	fmt.Println(f(2))
	fmt.Println(f(3))

	f2 := makeSuffix(".jpg")
	fmt.Println(f2("winter"))
	fmt.Println(f2("hello.jpg"))

	fmt.Println(makeSuffix2("winter", ".jpg"))
	fmt.Println(makeSuffix2("hello.jpg", ".jpg"))
}